
package com.kanjian.music.adapter;

import com.android.volley.toolbox.NetworkImageView;
import com.kanjian.music.R;
import com.kanjian.music.entity.Recommend;
import com.kanjian.music.entity.TopList;
import com.kanjian.music.volley.VolleyQueue;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 推荐页ListAdapter
 * 
 * @author xuyanjun@kanjian.com
 */
public class TopListListAdapter extends MusicSubFragmentListAdapater<TopList> {

    public TopListListAdapter(Context context) {
        super(context);
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return VIEW_TYPE_FAKE;
        } else {
            return VIEW_TYPE_DATA;
        }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        super.getView(position, convertView, parent);
        if (getItemViewType(position) == VIEW_TYPE_FAKE) {
            return mListFakeView;
        } else {
            ViewHolder holder;
            if (convertView == null || convertView.getTag() == null) {
                holder = new ViewHolder();
                convertView = mLayoutInflater.inflate(R.layout.item_list_rank, null);
                holder.mTv_title = (TextView) convertView.findViewById(R.id.item_list_rank_title);
                holder.mTv_desc = (TextView) convertView.findViewById(R.id.item_list_rank_desc);
                holder.mIv_pic = (NetworkImageView) convertView
                        .findViewById(R.id.item_list_rank_pic);
                holder.mIv_pic.setDefaultImageResId(R.drawable.default_image_small);
                holder.mIv_play = (ImageView) convertView
                        .findViewById(R.id.item_list_rank_play_icon);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            TopList top = getItem(position);
            holder.mTv_title.setText(top.mTitle);
            holder.mTv_desc.setText(top.mDesc);
            holder.mIv_pic.setImageUrl(top.mPicUrl, VolleyQueue.getImageLoader());
            holder.mIv_play.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });
            return convertView;
        }
    }

    static class ViewHolder {
        TextView mTv_title;

        TextView mTv_desc;

        NetworkImageView mIv_pic;

        ImageView mIv_play;

    }

}
